package com.sbdemo.service.impl;

import com.sbdemo.bean.TestBean;
import com.sbdemo.dao.ITestDao;
import com.sbdemo.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by Administrator on 2017/3/7.
 */
@Service
public class ITestServiceImpl implements ITestService{

    @Autowired
    private ITestDao dao;

    @Override
    public boolean addTestBean(TestBean t) {
        TestBean result = dao.save(t);
        if (null != result){
            return true;
        }
        return false;
    }

    @Override
    public TestBean findOne(Long id) {
        return dao.findOne(id);
    }

    @Override
    public List<TestBean> findAll() {
        return (List<TestBean>) dao.findAll();
    }

    @Override
    public boolean delTestBean(Long[] ids) {
        if (ids != null){
            for (Long id : ids){
             dao.delete(id);
            }
            return true;
        }
        return false;
    }

    @Transactional
    @Override
    public boolean updateTestBean(TestBean t) {
        if (null != t){
            dao.update(t.getName(),t.getAge(),t.getId());
            return true;
        }
        return false;
    }
}
